<?php

namespace app\common\service;
use app\admin\model\Order;
use app\common\model\Cart;
use app\admin\model\Goods;
use app\admin\model\GoodsSpecs;
use app\admin\model\UserCoupon;
use think\Service;

class PayNotifyService
{
		function wxNotify($ordermark = '',$trade_id = ''){
				$os = Order::where("ordermark",$ordermark)->update(['is_pay'=>1,'tradernum'=>$trade_id]);
				if($os){
					  Order::where("ordermark",$ordermark)->update(['pay_time'=>date("Y-m-d H:i:s")]);
					  Cart::where("guan_oid",$order['oid'])->update(['is_pay'=>1]);

					  $order = Order::where("ordermark",$ordermark)->find();
					  $cart = Cart::where("guan_oid",$order['oid'])->select();
					  foreach($cart as &$v){
					  	  Goods::where("id",$v['pro_id'])->setDec("stock",$v['pro_num']);
					  	  Goods::where("id",$v['pro_id'])->setInc("sell_num",$v['pro_num']);
					  	  if(!empty($v['can']) && $v['can']!='默认'){
					  	  	   GoodsSpecs::where(['goods_id'=>$v['pro_id'],'name'=>$v['can']])->setDec("stock",$v['pro_num']);
					  	  } 
					  }

					  if($order['qid']){
					  		UserCoupon::where("id",$order['qid'])->update(['is_use'=>1,'use_time'=>time()]);
					  }
				}
		}
}